//分页参数
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 20,
  currentPage: 1
};

// 和网络交互相关的参数
let params = {
  id:'',
  userEmail: '',
  userName:'',
};

const validateEmail = (rule, value, callback) => {
  if (value.indexOf(".")==-1) {
    callback(new Error('域名格式不正确'));
  } else {
    callback();
  }
};

let status={
  modalDelete:{
    isShow: false,
    isLoading: false,
    title:'用户',
    email:{
      id:'',
      userName:'',
      userEmail:'',
    },
  },
  modalAdd:{
    isShow: false,
    isLoading: false,
  },
  ruleValidate: {
    userEmail: [
      { required: true, message: '邮箱不能为空', trigger: 'blur' },
      { type: 'email', message: '邮箱格式不正确', trigger: 'blur' }
    ],
    domain: [
      { required: true, message: '域名不能为空', trigger: 'blur' },
      { validator:validateEmail, trigger: 'blur' }
    ],
  }
}



// 页面的数据源
let data = {
  blacklist: [],
  email:{
    userEmail: '',
    domain:'',
    userName:'',
    label:'邮箱',
    type:1,
    reason:[],
  },
  tagList:[
    {
      value: '广告推广',
      label: '广告推广'
    },
    {
      value: '钓鱼邮件',
      label: '钓鱼邮件'
    }, {
      value: '仿冒邮件',
      label: '仿冒邮件'
    },
  ],
  typeList:[
    {
      value: '1',
      label: '邮箱'
    },
    {
      value: '2',
      label: '域名'
    }
  ],
};

const tableRowActionEdit = function (self) {
  return {
    title: '操作',
    key: 'action',
    width: 120,
    align:'center',
    render: (h, params) => {
      return (
        <div>
          < i-button type="error" size="small"  style="margin-right:10px" onClick={() => {self.deleteAction(params.index)}}>移除黑名单</i-button>
        </div>
      );

    }
  }
};

let table = function (self) {
  return [
    {
      title: '序号',
      type: 'index',
      width: 80,
      align: 'center',
    },
    {
      title: '邮箱',
      align: 'center',
      key: 'userEmail',
      width: 180,
    },
    {
      title: '内部邮箱',
      align: 'center',
      key: 'virtualName',
      minWidth: 250,
    },
    {
    title: '类型',
      key: 'type',
      width: 80,
      align:'center',
      render: (h, params) => {
      let type = params.row.type;
      let typeName = "";
      if (type===1){
        typeName = "邮箱";
      }
      if (type===2){
        typeName = "域名";
      }
      return h('div',typeName);
    }
  },
    {
      title: '拉黑原因',
      align: 'center',
      key: 'reason',
      width: 200,
    },
    {
      title: '拉黑人',
      width: 110,
      key: 'createName',
      align: 'center'
    },
    {
      title: '拉黑时间',
      align: 'center',
      width: 180,
      key: 'createTime',
    },
    self.$authority("EMAIL-3-101")?tableRowActionEdit(self):null
  ];
}

export  default  {
  tPage: page,
  tParam: params,
  tData: data,
  tStatus: status,
  tTable:table,
};
